package org.springblade.modules.notice.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springblade.modules.notice.vo.CommonEnumInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author ysq
 * @Date 2024/11/22
 * @Description 触发条件枚举
 */
@Getter
@AllArgsConstructor
public enum TriggerConditionEnum {

	CONDITION_1(1, BusinessType.REPAIR.getCode(), TriggerNodeEnum.CREATE.getCode(), "当pc客服选择审批报障/物业人员/维保员/游客提交报障后"),

	CONDITION_2(2, BusinessType.REPAIR.getCode(), TriggerNodeEnum.ASSIGN.getCode(), "当任务指派执行人/审批重新分派人员/转派人员/增派人员"),

	CONDITION_3(3, BusinessType.REPAIR.getCode(), TriggerNodeEnum.SIGN_IN.getCode(), "当维修任务开始后，预计维修结束时间前5分钟，还未签退"),

	CONDITION_4(4, BusinessType.REPAIR.getCode(), TriggerNodeEnum.APPROVE_PASS.getCode(), "当维保经理/维保组长，任务审批通过，指派任务执行人后"),

	CONDITION_5(5, BusinessType.REPAIR.getCode(), TriggerNodeEnum.APPROVE_NOT_PASS.getCode(), "当维保经理/维保组长，任务审批不通过"),

	CONDITION_6(6, BusinessType.REPAIR.getCode(), TriggerNodeEnum.CREATE.getCode(), "任务指派后，已停梯1小时，工单未签到"),

	CONDITION_7(7, BusinessType.REPAIR.getCode(), TriggerNodeEnum.CREATE.getCode(), "任务指派后，已停梯2小时，工单未签到"),

	CONDITION_8(8, BusinessType.REPAIR.getCode(), TriggerNodeEnum.CREATE.getCode(), "任务指派后，已停梯4小时，工单未签到"),

	CONDITION_9(9, BusinessType.REPAIR.getCode(), TriggerNodeEnum.SIGN_IN.getCode(), "任务签到时，电梯状态“已停梯”变更至“正常”"),

	CONDITION_10(10, BusinessType.REPAIR.getCode(), TriggerNodeEnum.SIGN_IN.getCode(), "停梯的任务已签到开始后，作业2小时，未签退"),

	CONDITION_11(11, BusinessType.REPAIR.getCode(), TriggerNodeEnum.SIGN_IN.getCode(), "停梯的任务已签到开始后，作业4小时，未签退"),

	CONDITION_12(12, BusinessType.REPAIR.getCode(), TriggerNodeEnum.SIGN_OUT.getCode(), "停梯的任务，完成已签退"),

	CONDITION_13(13, BusinessType.REPAIR.getCode(), TriggerNodeEnum.FINISH.getCode(), "当维保员-完成任务"),

	CONDITION_14(14, BusinessType.REPAIR.getCode(), TriggerNodeEnum.REMINDER.getCode(), "当用户点击催办"),

	CONDITION_15(15, BusinessType.REPAIR.getCode(), TriggerNodeEnum.CLOSE.getCode(), "当物业用户点击关闭工单"),

	CONDITION_16(16, BusinessType.ABARBEITUNG.getCode(), TriggerNodeEnum.ASSIGN.getCode(), "当任务指派执行人/转派人员"),

	CONDITION_17(17, BusinessType.ABARBEITUNG.getCode(), TriggerNodeEnum.REOPEN.getCode(), "当任务重新打开"),

	CONDITION_18(18, BusinessType.RESCUE.getCode(), TriggerNodeEnum.CREATE.getCode(), "创建救援工单"),

	CONDITION_19(19, BusinessType.RESCUE.getCode(), TriggerNodeEnum.CREATE.getCode(), "超出设置调度时长，未完成调度"),

	CONDITION_20(20, BusinessType.RESCUE.getCode(), TriggerNodeEnum.CREATE.getCode(), "项目要求时间-到达现场及时<预警阈值"),

	CONDITION_21(21, BusinessType.RESCUE.getCode(), TriggerNodeEnum.CREATE.getCode(), "超出项目规定时间或30分未签到"),

	CONDITION_22(22, BusinessType.RESCUE.getCode(), TriggerNodeEnum.ASSIGN.getCode(), "当任务指派人"),

	CONDITION_23(23, BusinessType.RESCUE.getCode(), TriggerNodeEnum.ASSIGN.getCode(), "当任务增派人"),

	CONDITION_24(24, BusinessType.RESCUE.getCode(), TriggerNodeEnum.ASSIGN.getCode(), "超出确认出发时长或者长时间不移动"),

	CONDITION_25(25, BusinessType.RESCUE.getCode(), TriggerNodeEnum.SIGN_IN.getCode(), "超出项目规定时间或30分后才签到"),

	CONDITION_26(26, BusinessType.RESCUE.getCode(), TriggerNodeEnum.CANCEL.getCode(), "工单撤销"),
	;

	private final Integer code;

	/**
	 * 业务类型
	 */
	private final Integer businessType;

	/**
	 * 触发节点
	 */
	private final Integer triggerNode;

	private final String desc;

	public static String getDesc(Integer code) {
		for (TriggerConditionEnum value : TriggerConditionEnum.values()) {
			if (value.getCode().equals(code)) {
				return value.getDesc();
			}
		}
		return null;
	}

	/**
	 * 获取可选列表
	 */
	public static List<CommonEnumInfo> getSelectList(Integer businessType) {
		List<CommonEnumInfo> list = new ArrayList<>(16);
		for (TriggerConditionEnum value : values()) {
			if (value.getBusinessType().equals(businessType)) {
				list.add(new CommonEnumInfo(value.getCode(), value.getDesc()));
			}
		}
		return list;
	}

	/**
	 * 根据触发节点获取触发条件code列表
	 * @param triggerNode
	 * @return
	 */
	public static List<Integer> getCodesByTriggerNode(Integer triggerNode) {
		List<Integer> list = new ArrayList<>(16);
		for (TriggerConditionEnum value : values()) {
			if (value.getTriggerNode().equals(triggerNode)) {
				list.add(value.getCode());
			}
		}
		return list;
	}

}
